﻿@using OBUCare.Web.Infrastructure;
@using OBUCare.Core.Models;
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@using OBUCare.Core.Common;
@{
    ViewBag.Title = "元器件销售信息管理";

    var operatorInfo = UIUtility.GetCurrentUser();

    var menuName = PageData["moduleID"] == null ? UIUtility.getMenuName(Request.RawUrl) : PageData["moduleID"];
    ViewData["menuName"] = menuName;
}
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
<table width="100%">
    <tr>
        <td style="text-align: center">
            <span style="font-weight: bold; font-size: 16px">元器件销售信息管理</span>
        </td>
    </tr>
    <tr>
        <td>
            @Html.Partial("_PartsSaleSearch")
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid<View_PARTS_SALE>()
            .Name("Grid")
            .DataKeys(keys => keys.Add(c => c.ID))
            .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
            .Resizable(resizing => resizing.Columns(false))
            .DataBinding(dataBinding => dataBinding
                .Ajax().Select("ListPartsSale", "Parts", new { sql = "" })
                )
            .Columns(columns =>
            {
                columns.Bound(o => o.PARTS_NAME).Width("7%");
                columns.Bound(o => o.OBU_NO).Width("11%");
                columns.Bound(o => o.VEHICLE_PLATE_NO).Width("9%");
                columns.Bound(o => o.USER_NAME).Width("19%");
                columns.Bound(o => o.OBU_REGISTE_DATE).Format("{0:yyyy-MM-dd}").Width("9%");
                columns.Bound(o => o.AMOUNT).Width("5%");
                columns.Bound(o => o.REPORT_DATE).Width("9%");
                columns.Bound(o => o.AGENT_NAME).Width("9%");
                columns.Bound(o => o.OPERATOR_NAME).Width("9%");
                columns.Bound(o => o.ID)
                .ClientTemplate("<input type='button' value='删除' name='deleteAll' id='<#= ID #>' dt='<#= CREATED_DATE #>' onclick='deleteData(id,dt)' />").Title("删除").Width("10%");
            })
            .ClientEvents(events =>
                {
                    events.OnError("onError");
                    events.OnDataBinding("onDataBinding");
                })
            .TableHtmlAttributes(new { style = "width:150%" })
                                   .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
                                   .Footer(true)
                                             .Pageable(paging =>
                                             {
                                                 paging.Style(CommonStyleForUI.Grid_PageStyle)
                                                 .Position(CommonStyleForUI.Grid_PagePosition)
                                                 .PageTo(CommonStyleForUI.Grid_CurrentPage)
                                                 .PageSize(CommonStyleForUI.Grid_PageSize, new int[] { 10, 20, 50, 100, 200, 500 });
                                             })
                            )
        </td>
    </tr>
</table>
<!--删除弹出填写备注窗口-->
@{  Html.Telerik().Window()
        .Name("Window")
        .Title("确定删除？")
        .Content(@<text>
    <form id="delForm">
        <div>
            <p>
                <label for="txtRemark">
                    备注 <span style="color: red">*</span></label>
                <input type="hidden" id="HidbillID" style="width: 0px;" />
            </p>
            <p>
                <div>
                    <textarea id="txtRemark" class="{required:true,messages:{required:'请输入内容'}}" style="width: 370px; height: 100px;"></textarea>
                </div>
                <div>
                    <span id="valRemark" style="color: red">请输入备注</span>
                </div>
            </p>
            <div style="float: right">
                <button type="button" id="btnSumitDeleteForm" class="t-button t-state-default">
                    提交</button>
            </div>
        </div>
    </form>
    </text>)
        .Width(420)
        .Height(260)
        .Draggable(true)
        .Modal(true)
        .Visible(false)
        .Render();
}
<script language="javascript" type="text/javascript">
    $(function () {
        $("#btnSumitDeleteForm").click(function () {
            confirmDelete();
        });
    });
    function onError(e) {
        //debugger;
        e.preventDefault();
        /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
        else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
        else*/
        alert(e.XMLHttpRequest.getResponseHeader("message"));
    }


    function onDataBinding(e) {
        var grid = $('#Grid').data('tGrid')
        index = (grid.currentPage - 1) * grid.pageSize;
        e.data = {
            // the key ("category") specifies the variable name of the action method which will contain the specified value
            searchSql: $('#searchSql').val(),
            agentNO: $('#agentNO').val()
            , menuNames: $('#menuNames').val()
        };
    }

    function deleteData(id, dt) {
        var myDate = new Date(Date.parse(dt.replace(/-/g, "/")));
        var now = new Date();

        if (myDate.getFullYear() == now.getFullYear() && myDate.getMonth() == now.getMonth() && myDate.getDay() == now.getDay()) {
            if (confirm("确定删除？")) {
                $("#HidbillID").val(id);
                $("#valRemark").hide();
                $('#Window').data('tWindow').center().open();
                ////debugger;

            }
        }
        else {
            alert("只能删除今日的维修操作！");
        }
    }

    function confirmDelete() {
        var id = $("#HidbillID").val();
        var agentNo = $('#AgentNo').val();
        var txtRemark = $("#txtRemark").val();

        if (!txtRemark.StringIsNullOrEmpty()) {
            var jdata = { ID: id, Remark: txtRemark };
            $.post("/Parts/DeleteData", jdata,
                        function (data) {
                            if (data.Success == true) {
                                var grid = $('#Grid').data('tGrid');
                                //                                alert(grid);
                                grid.rebind();
                                alert(data.ErrorMsg);
                                $('#Window').data('tWindow').center().close();
                            }
                            else {
                                alert(data.ErrorMsg);
                            }
                        });
        }
        else {
            $("#valRemark").show();
        }
    }

</script>
